package butines.core.game;

import java.awt.Graphics2D;

public class ImageCursor implements GameCursor {

	private float countdown;
	private int frame;
	private int numFrame;
	
	private float x, y;
	private ImageSheet imageSheet;
	private Image curr;
	
	public ImageCursor(Image image, int numFrame) {
		this.imageSheet = new ImageSheet(image, 128, 128);
		this.numFrame = numFrame;
		this.curr = imageSheet.getImage(0);
	}

	public void update(float mousex, float mousey, float t) {
		x = mousex;
		y = mousey;
		countdown += t;
		if (countdown >= .1f) {
			countdown %= .1f;
			frame = (frame + 1 >= numFrame) ? 0 : frame + 1;
			curr = imageSheet.getImage(frame);
		}
	}

	public void draw(Graphics2D g) {
		curr.draw(g, x, y);
	}
	
}
